const assessmentService = require('../services/assessmentService');

const assessmentController = {
  // 创建新测评（心理测评）
  async createAssessment(ctx) {
    try {
      const { title, description, duration } = ctx.request.body;
      
      // 验证输入
      if (!title || !duration) {
        ctx.throw(400, '标题和时长是必填项');
      }
      
      const result = await assessmentService.createAssessment({
        title,
        description,
        duration
      });
      
      ctx.status = 201;
      ctx.body = {
        message: '心理测评创建成功',
        ...result
      };
    } catch (error) {
      ctx.throw(400, error.message);
    }
  },

  // 获取所有测评
  async getAllAssessments(ctx) {
    try {
      const assessments = await assessmentService.getAllAssessments();
      ctx.status = 200;
      ctx.body = assessments;
    } catch (error) {
      ctx.throw(500, error.message);
    }
  },

  // 获取测评详情
  async getAssessmentById(ctx) {
    try {
      const { id } = ctx.params;
      const assessment = await assessmentService.getAssessmentById(id);
      ctx.status = 200;
      ctx.body = assessment;
    } catch (error) {
      ctx.throw(404, error.message);
    }
  }
};

module.exports = assessmentController;